<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <script type="text/javascript" src="../../common/js/public.js"></script>
    <script type="text/javascript" src="../../common/js/publicUtils.js"></script>
    <!--<![endif]&ndash;&gt;-->
    <style>
        .menudiv .layui-input-inline,.buttondiv .layui-input-inline {
            float: left;
            width: 450px !important;
            margin-right: 10px;
        }
        .buttondiv{
            display: none;
        }
        .ztreeuldiv {
            height: 100%;
            width: 100%;
            background-color: white;
        }

    </style>
</head>
<body>
<div class="layui-fluid" id="flowDiv" onload="onLoad()" >
    <div class="zTreeBackground left" style="float: left;width:400px">
        <input type="checkbox" id="retain" value="1" name="retain"><span>原单位保留</span>
        <div class="searchdiv" style="margin-top: 5px">
            <div class="layui-input-inline" style="width: 100%">
                <input type="search" id="keyword" name="keyword" autocomplete="off" class="layui-input" placeholder="请输入关键字查询"/>
                <i onclick="searchByName()" class="layui-icon layui-icon-search" style="position: absolute;top:8px;right: 8px;"></i>
            </div>
        </div>
        <div class="ztreediv" id="ztreediv" style="overflow:auto">
            <ul id="treeStructure" class="ztree"></ul>
        </div>
    </div>
</div>
</body>
<SCRIPT type="text/javascript">
    var zTreeObj,zTreeObj_input,zTreeObj_input_button;
    var form;
    var table;

    layui.use(['form', 'layer'], function() {
        form = layui.form;
        layer = layui.layer;
        table = layui.table;
    })
    $(document).ready(function(){
        loadTree();
    });

    window.onload = getContentSize;
    window.onresize = getContentSize;

    /**
     * 页面自适应
     */
    function getContentSize() {
        var wh = document.documentElement.clientHeight;
        var eh = 30;
        ch = (wh - eh) + "px";
        document.getElementById( "flowDiv" ).style.height = ch;
        document.getElementById( "ztreediv" ).style.height = (wh - eh - 50)+"px";
        document.body.style.height = (wh)+"px";
    }

    /**
     * 保存
     */
    function submit(index, layero,ids){
        var retain;
        if ($('#retain').attr('checked')) {
            retain=true;
        }else {
            retain=false;
        }
        var checkedNodes = zTreeObj.getCheckedNodes();
        if(checkedNodes.length<=0){
            layer.alert("请选择组织");
            return;
        }
        console.log(checkedNodes[0]);
        var orgids=new Array();
        for(var i=0;i<checkedNodes.length;i++){
            if(checkedNodes[i].type!=3&&checkedNodes[i].type!=2) {
                layer.alert("请选择部门或虚拟组织");
                return;
            }
            orgids[i]=checkedNodes[i].id;
        }
        var result;
        publicAjax ("post","/orgPerson/moveOrgPerson",{   ids:ids,orgids:orgids, retain:retain}
        ,false,null,function (r) {
                result=r;
        });

        if(result.code==2000){
            laysuccess("移动成功");
        }else{
            layerror("移动失败");
        }
        return result;

    }

    function query() {
        var keyword = $("#keyword").val();
        if (keyword === "") {
            //显示上次搜索后背隐藏的结点
            zTreeObj.getNodesByParam("isHidden", true);
            zTreeObj.showNodes(nodes);
            return;
        }

        var zTree = zTreeObj;
        var allNodes = zTree.transformToArray(zTree.getNodes());
        zTree.hideNodes(allNodes);    //当开始搜索时，先将所有节点隐藏

        var nodeList = zTree.getNodesByParamFuzzy('name', keyword, 0);    //通过关键字模糊搜索
        var arr = new Array();
        for (var i = 0; i < nodeList.length; i++) {
            arr = $.merge(arr, nodeList[i].getPath());    //找出所有符合要求的叶子节点的路径
        }
        zTree.showNodes($.unique(arr));    //显示所有要求的节点及其路径节点
        zTree.expandAll(true);    //展开路径
    }

    <!-- 高亮显示查询结束 -->
    function searchByName(){
        var search = $("#keyword").val();
        if(!search){
            return ;
        }
        $("#treeStructure").html('');
        publicAjax (null,'company/getOrgForTree',{"shortName":$("#keyword").val()},false,null,function(data){
            zTreeObj = $.fn.zTree.init($("#treeStructure"),setting, changeIcon(data.data));
            zTreeObj.expandAll(true);
        })
    }

    /**
     * 左侧树设置
     * @type {{check: {enable: boolean}, data: {simpleData: {enable: boolean, idKey: string, pIdKey: string, isParent: string, rootPid: number}}, callback: {beforeClick: zTreeBeforeClick, onClick: zTreeOnClick}}}
     */
    var setting = {
        check: {
            enable: true,
            chkboxType:  { "Y": "", "N": "" }
        },
        edit:{
            enable: false,
        },
        // async: {
        //     enable: true,
        //     url: "./sysmenu/selectMenuByPid",
        //     dataFilter: formatedata,
        //     autoParam: ["id"]
        // },
        data: {
            simpleData: {
                enable: true,
                idKey:"id",
                pIdKey:"parentId",
                isParent:"parent",
                rootPid:-1
            },
            key: {
                url: "xUrl",
                icon:"xIcon",
                name:"shortName"
            }
        },
        callback: {
            // beforeClick: zTreeBeforeClick,
            // onClick: zTreeOnClick
        }
    };



    /**
     * 加载左侧树
     * type 0:不展开节点
     *      1:展开全部节点
     *
     */
    function loadTree(keyWord,type){
        publicAjax ("post","/orgPerson/selectOrgTree",{name: keyWord},null,null,function (r) {
            var jsondata = r.data;
            // jsondata.push(json);
            zTreeObj = $.fn.zTree.init($("#treeStructure"), setting, changeIcon(jsondata));
            // zTreeObj.expandAll(true);
            var treeObj = zTreeObj;
            var nodes = treeObj.getNodes();
            if (nodes.length>0) {
                for (var i = 0; i < nodes.length; i++) {
                    treeObj.expandNode(nodes[i], true, false, false);
                }
            }
        });
    }




    function getUrlParam(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return decodeURIComponent(r[2]);
        return null;
    }



</SCRIPT>
</html>